package com.funcourse.demo.api.restful.io.response;

import com.funcourse.demo.model.CompeteRoom;
import com.funcourse.demo.model.room.AttenderRoomRelation;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AttendedRoom {

  CompeteRoom competeRoom;

  @ApiModelProperty("参加时间，毫秒timestamp")
  Long attendedTime;

  public static List<AttendedRoom> buildAttendedRooms(List<AttenderRoomRelation> attenderRoomRelations,Iterable<CompeteRoom> competeRooms){

    List<AttendedRoom> attendedRooms = new ArrayList<>();
    competeRooms.forEach(cr -> {

      for(int i=0;i<attenderRoomRelations.size();i++){
        if(cr.getId().equalsIgnoreCase(attenderRoomRelations.get(i).getRoomId())){
          //减少带宽
          cr.setUserWithScoreList(new ArrayList<>(0));
          attendedRooms.add(new AttendedRoom(cr,attenderRoomRelations.get(i).getAttendTime()));
          break;
        }
      }

    });
    attendedRooms.sort(Comparator.comparing(AttendedRoom::getAttendedTime).reversed());
    return attendedRooms;

  }



}
